package com.subfg.common.rabbitmq.constant;


import com.subfg.common.constant.TimeEnum;
import com.subfg.common.util.common.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "统一封装队列消息", description = "用于队列消费失败后的异常(错误等)日志记录, 方便排查")
public class QueueContentModel<T> implements Serializable {
    @ApiModelProperty(value = "队列全系统唯一id")
    private String id;
    @ApiModelProperty(value = "消息主题")
    private Integer subject;
    @ApiModelProperty(value = "发送队列数据")
    private T data;
    @ApiModelProperty(value = "是否为重复消息状态 [0 不是 1: 是  2 重发消息]")
    private Integer status;
    @ApiModelProperty(value = "消费次数, 可自定义消费多少后, 手动确认消息, 并使用推送等方式及时提醒管理员")
    private Integer count;
    @ApiModelProperty(value = "第一次发送时间")
    private Long sendDate;
    @ApiModelProperty(value = "延迟时间")
    private Long delayTime;

    @ApiModelProperty(value = "队列路由")
    private String exchange;
    @ApiModelProperty(value = "队列名称")
    private String queueName;
    @ApiModelProperty(value = "最后一次消费时间")
    private Long lastDate;
    @ApiModelProperty(value = "成功消费时间")
    private Long successDate;
    @ApiModelProperty(value = "异常错误类名")
    private String exceptionName;
    @ApiModelProperty(value = "详细异常错误信息")
    private String exceptionInfo;
    @ApiModelProperty(value = "是否为延迟队列")
    private boolean isDelayQueue;

    public QueueContentModel(String id, Integer status, T data) {
        this.id = id;
        this.data = data;
        this.status = status;
        this.count = 0;
        this.sendDate = TimeUtil.getCurrentTime();
    }


    public QueueContentModel(String id, Integer subject, Integer status, T data) {
        this.id = id;
        this.subject = subject;
        this.data = data;
        this.status = status;
        this.count = 0;
        this.sendDate = TimeUtil.getCurrentTime();
    }


    public QueueContentModel(String id, T data, Integer delayCount) {
        this.id = id;
        this.status = 0;
        this.count = 0;
        this.data = data;
        this.delayTime = TimeUtil.getTimeEnumTimeStamp(delayCount, TimeEnum.MINUTE);
    }

    public QueueContentModel(QueueContentModel queueContentModel) {
        this.id = queueContentModel.getId();
        this.status = queueContentModel.getStatus();
        this.count = queueContentModel.getCount();
        this.sendDate = queueContentModel.getSendDate();
        this.subject = queueContentModel.getSubject();
    }
}
